﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using Bll;
using System.Data;

namespace 财会系.Admin.Email
{
    public partial class Emailadmin : System.Web.UI.Page
    {
        BllEmail b = new BllEmail();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (Request.QueryString["Id"] != null)
                {
                    ModelPublic m = new ModelPublic();
                    m.Id = Request.QueryString["Id"].ToString();
                    lblId.Text = m.Id;
                    datashow(m);
                }
                else
                {
                    Response.Redirect("../Email/EmailShow.aspx");
                }


            }
        }

        public void datashow(ModelPublic m)
        {
            m.Id = lblId.Text;
            DataTable dt = b.Email_Inquire_Single(m);
            foreach (DataRow my in dt.Rows)
            {
                txtType.Text = my["Type"].ToString();
                txtName.Text = my["Name"].ToString();
                txtQQ.Text = my["QQ"].ToString();
                txtPhone.Text = my["Phone"].ToString();
                txtEmail.Text = my["EmailAdress"].ToString();
                txtTitle.Text = my["Title"].ToString();
                txtAdress.Text = my["adress"].ToString();
                txtContent.Text = my["_Content"].ToString();
                txtDateTime.Text = my["DateTime"].ToString();
            }
            string Handle = b.Email_Handle_Search(m);
            if (Handle == "未处理" || Handle == "未阅读")
            {
                RadioButton1.Checked = true;
            }
            if (Handle == "处理中")
            {
                RadioButton2.Checked = true;
            }
            if (Handle == "已处理")
            {
                RadioButton3.Checked = true;
            }
        }

        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Modify();
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Modify();
        }

        private void Modify()
        {
            if (Request.QueryString["Id"] != null)
            {
                ModelPublic m = new ModelPublic();
                m.Id = Request.QueryString["Id"].ToString();
                if (RadioButton1.Checked == true)
                {
                    m.Handle = RadioButton1.Text;
                }
                if (RadioButton2.Checked == true)
                {
                    m.Handle = RadioButton2.Text;
                }
                if (RadioButton3.Checked == true)
                {
                    m.Handle = RadioButton3.Text;
                }

                if (b.Email_Handle_Modify(m))
                {
                    Response.Redirect("../Email/EmailShow.aspx");
                }
                else
                {
                    Response.Write("<script>alert('处理失败！请联系维护人员！')</script>");
                }
            }
        }
    }
}